| Total Complexity | 2 |
| Total Lines | 19 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import {Inject} from '@nestjs/common'; |
||
| 8 | |||
| 9 | @CommandHandler(CreateTaskCommand) |
||
| 10 | export class CreateTaskCommandHandler { |
||
| 11 | constructor( |
||
| 12 | @Inject('ITaskRepository') |
||
| 13 | private readonly taskRepository: ITaskRepository, |
||
| 14 | private readonly isTaskAlreadyExist: IsTaskAlreadyExist |
||
| 15 | ) {} |
||
| 16 | |||
| 17 | public async execute(command: CreateTaskCommand): Promise<string> { |
||
| 18 | const {name} = command; |
||
| 19 | |||
| 20 | if (true === (await this.isTaskAlreadyExist.isSatisfiedBy(name))) { |
||
| 21 | throw new TaskAlreadyExistException(); |
||
| 22 | } |
||
| 23 | |||
| 24 | const task = await this.taskRepository.save(new Task(name)); |
||
| 25 | |||
| 26 | return task.getId(); |
||
| 27 | } |
||
| 29 |